package com.xx.happychatboot.serve.user.mapper;

import com.xx.happychatboot.serve.user.domain.entity.SysRole;
import io.mybatis.mapper.Mapper;
import io.mybatis.mapper.base.EntityProvider;
import io.mybatis.provider.Caching;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Lang;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author xiaoXuan
 * @since 2024-12-10
 */
public interface SysRoleMapper extends Mapper<SysRole, Long> {

    /**
     * 通过用户ID获取用户角色
     * @param userId
     * @return
     */
    List<SysRole> getRolesByUid(@Param("userId") Long userId);

    /**
     * 通过URL获取角色名
     * @param url
     * @return
     */
    List<String> getRoleByUrl(String url);

    /**
     * 通过角色code查询角色信息
     * @param code
     * @return
     */
    SysRole selectByRoleCode(@Param("roleCode") String code);

    @Override
    @Lang(Caching.class)
    @Options(useGeneratedKeys = true, keyProperty = "roleId")
    @InsertProvider(type = EntityProvider.class, method = "insert")
    <S extends SysRole> int insert(S entity);

    @Override
    @Lang(Caching.class)
    @Options(useGeneratedKeys = true, keyProperty = "roleId")
    @InsertProvider(type = EntityProvider.class, method = "insert")
    <S extends SysRole> int insertSelective(S entity);
}
